from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-10 14:16:43.622107
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 10, Oct, 2022
Time: 14:16:49
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.6640
Nobs: 805.000 HQIC: -50.9870
Log likelihood: 10413.1 FPE: 5.87693e-23
AIC: -51.1884 Det(Omega_mle): 5.25890e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296946 0.052746 5.630 0.000
L1.Burgenland 0.109223 0.035473 3.079 0.002
L1.Kärnten -0.106413 0.018888 -5.634 0.000
L1.Niederösterreich 0.210096 0.074187 2.832 0.005
L1.Oberösterreich 0.100159 0.071165 1.407 0.159
L1.Salzburg 0.251521 0.037821 6.650 0.000
L1.Steiermark 0.038139 0.049486 0.771 0.441
L1.Tirol 0.106285 0.040130 2.649 0.008
L1.Vorarlberg -0.059158 0.034495 -1.715 0.086
L1.Wien 0.057739 0.063561 0.908 0.364
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064261 0.109205 0.588 0.556
L1.Burgenland -0.033639 0.073444 -0.458 0.647
L1.Kärnten 0.047828 0.039106 1.223 0.221
L1.Niederösterreich -0.172561 0.153597 -1.123 0.261
L1.Oberösterreich 0.385378 0.147339 2.616 0.009
L1.Salzburg 0.287157 0.078305 3.667 0.000
L1.Steiermark 0.106031 0.102455 1.035 0.301
L1.Tirol 0.313476 0.083085 3.773 0.000
L1.Vorarlberg 0.025303 0.071418 0.354 0.723
L1.Wien -0.016599 0.131596 -0.126 0.900
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189850 0.027076 7.012 0.000
L1.Burgenland 0.090212 0.018210 4.954 0.000
L1.Kärnten -0.008439 0.009696 -0.870 0.384
L1.Niederösterreich 0.264520 0.038083 6.946 0.000
L1.Oberösterreich 0.126476 0.036531 3.462 0.001
L1.Salzburg 0.047390 0.019415 2.441 0.015
L1.Steiermark 0.016970 0.025403 0.668 0.504
L1.Tirol 0.094272 0.020600 4.576 0.000
L1.Vorarlberg 0.059358 0.017707 3.352 0.001
L1.Wien 0.120453 0.032628 3.692 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110058 0.027752 3.966 0.000
L1.Burgenland 0.044244 0.018664 2.371 0.018
L1.Kärnten -0.016094 0.009938 -1.619 0.105
L1.Niederösterreich 0.192940 0.039033 4.943 0.000
L1.Oberösterreich 0.294338 0.037443 7.861 0.000
L1.Salzburg 0.115061 0.019899 5.782 0.000
L1.Steiermark 0.099776 0.026037 3.832 0.000
L1.Tirol 0.116306 0.021114 5.508 0.000
L1.Vorarlberg 0.070673 0.018149 3.894 0.000
L1.Wien -0.027686 0.033442 -0.828 0.408
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128789 0.050323 2.559 0.010
L1.Burgenland -0.051149 0.033844 -1.511 0.131
L1.Kärnten -0.040279 0.018021 -2.235 0.025
L1.Niederösterreich 0.170293 0.070780 2.406 0.016
L1.Oberösterreich 0.137578 0.067896 2.026 0.043
L1.Salzburg 0.285559 0.036084 7.914 0.000
L1.Steiermark 0.034869 0.047213 0.739 0.460
L1.Tirol 0.164208 0.038287 4.289 0.000
L1.Vorarlberg 0.103867 0.032910 3.156 0.002
L1.Wien 0.068526 0.060641 1.130 0.258
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060051 0.039896 1.505 0.132
L1.Burgenland 0.038513 0.026832 1.435 0.151
L1.Kärnten 0.050657 0.014287 3.546 0.000
L1.Niederösterreich 0.225744 0.056115 4.023 0.000
L1.Oberösterreich 0.282310 0.053828 5.245 0.000
L1.Salzburg 0.050777 0.028608 1.775 0.076
L1.Steiermark -0.007173 0.037431 -0.192 0.848
L1.Tirol 0.149844 0.030354 4.937 0.000
L1.Vorarlberg 0.071003 0.026091 2.721 0.007
L1.Wien 0.079213 0.048077 1.648 0.099
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178691 0.047684 3.747 0.000
L1.Burgenland -0.005854 0.032069 -0.183 0.855
L1.Kärnten -0.061085 0.017076 -3.577 0.000
L1.Niederösterreich -0.083601 0.067068 -1.247 0.213
L1.Oberösterreich 0.192779 0.064335 2.996 0.003
L1.Salzburg 0.056616 0.034192 1.656 0.098
L1.Steiermark 0.230836 0.044737 5.160 0.000
L1.Tirol 0.493664 0.036279 13.607 0.000
L1.Vorarlberg 0.049483 0.031184 1.587 0.113
L1.Wien -0.049175 0.057461 -0.856 0.392
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162234 0.054759 2.963 0.003
L1.Burgenland -0.011423 0.036827 -0.310 0.756
L1.Kärnten 0.065976 0.019609 3.365 0.001
L1.Niederösterreich 0.200580 0.077019 2.604 0.009
L1.Oberösterreich -0.060906 0.073881 -0.824 0.410
L1.Salzburg 0.216039 0.039265 5.502 0.000
L1.Steiermark 0.113732 0.051375 2.214 0.027
L1.Tirol 0.076877 0.041662 1.845 0.065
L1.Vorarlberg 0.124502 0.035811 3.477 0.001
L1.Wien 0.114490 0.065987 1.735 0.083
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353941 0.031861 11.109 0.000
L1.Burgenland 0.006148 0.021428 0.287 0.774
L1.Kärnten -0.023550 0.011409 -2.064 0.039
L1.Niederösterreich 0.223886 0.044813 4.996 0.000
L1.Oberösterreich 0.175533 0.042987 4.083 0.000
L1.Salzburg 0.046837 0.022846 2.050 0.040
L1.Steiermark -0.017245 0.029892 -0.577 0.564
L1.Tirol 0.108594 0.024240 4.480 0.000
L1.Vorarlberg 0.073573 0.020836 3.531 0.000
L1.Wien 0.053621 0.038394 1.397 0.163
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041149 0.152763 0.190315 0.157183 0.125100 0.113825 0.065667 0.227020
Kärnten 0.041149 1.000000 -0.002524 0.129738 0.041428 0.096118 0.429685 -0.053100 0.101382
Niederösterreich 0.152763 -0.002524 1.000000 0.336926 0.155228 0.300511 0.111034 0.183758 0.327630
Oberösterreich 0.190315 0.129738 0.336926 1.000000 0.232318 0.332755 0.172543 0.172525 0.263111
Salzburg 0.157183 0.041428 0.155228 0.232318 1.000000 0.146664 0.126903 0.148922 0.135690
Steiermark 0.125100 0.096118 0.300511 0.332755 0.146664 1.000000 0.153467 0.141065 0.079867
Tirol 0.113825 0.429685 0.111034 0.172543 0.126903 0.153467 1.000000 0.114847 0.155028
Vorarlberg 0.065667 -0.053100 0.183758 0.172525 0.148922 0.141065 0.114847 1.000000 0.007161
Wien 0.227020 0.101382 0.327630 0.263111 0.135690 0.079867 0.155028 0.007161 1.000000